package com.mongodb.service;

import com.mongodb.document.test.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zhangbowen
 * @date 2019/4/30
 **/
@Service
public class BookService {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Transactional
    public void test() {
        Book book = mongoTemplate.findOne(new Query(Criteria.where("_id").is("5bee844597e1950568d74ddb")), Book.class);
        Book book1 = mongoTemplate.findOne(new Query(Criteria.where("_id").is("5bee844597e1950568d74ddb")), Book.class);
    }
}
